home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / netinclude / net / if.h < prev    next >
C/C++ Source or Header  |  1994-02-04  |  10KB  |  281 lines

  1. #ifndef NET_IF_H
  2. #define NET_IF_H
  3. #define IF_H            /* XXX */
  4. /*
  5. **      $Filename: net/if.h $
  6. **    $Release$
  7. **      $Revision: 3.1 $
  8. **      $Date: 1994/02/03 11:56:05 $
  9. **
  10. **    Network interface
  11. **
  12. **    Copyright © 1993,1994 AmiTCP/IP Group, <AmiTCP-Group@hut.fi>
  13. **                  Helsinki University of Technology, Finland.
  14. **                  All rights reserved.
  15. */
  16.  
  17. /*
  18.  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
  19.  * All rights reserved.
  20.  *
  21.  * Redistribution and use in source and binary forms, with or without
  22.  * modification, are permitted provided that the following conditions
  23.  * are met:
  24.  * 1. Redistributions of source code must retain the above copyright
  25.  *    notice, this list of conditions and the following disclaimer.
  26.  * 2. Redistributions in binary form must reproduce the above copyright
  27.  *    notice, this list of conditions and the following disclaimer in the
  28.  *    documentation and/or other materials provided with the distribution.
  29.  * 3. All advertising materials mentioning features or use of this software
  30.  *    must display the following acknowledgement:
  31.  *    This product includes software developed by the University of
  32.  *    California, Berkeley and its contributors.
  33.  * 4. Neither the name of the University nor the names of its contributors
  34.  *    may be used to endorse or promote products derived from this software
  35.  *    without specific prior written permission.
  36.  *
  37.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  38.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  39.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  41.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  42.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  43.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  45.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  46.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47.  * SUCH DAMAGE.
  48.  *
  49.  *    @(#)if.h    7.11 (Berkeley) 3/19/91
  50.  */
  51.  
  52. /*
  53.  * Structures defining a network interface, providing a packet
  54.  * transport mechanism (ala level 0 of the PUP protocols).
  55.  *
  56.  * Each interface accepts output datagrams of a specified maximum
  57.  * length, and provides higher level routines with input datagrams
  58.  * received from its medium.
  59.  *
  60.  * Output occurs when the routine if_output is called, with three parameters:
  61.  *    (*ifp->if_output)(ifp, m, dst)
  62.  * Here m is the mbuf chain to be sent and dst is the destination address.
  63.  * The output routine encapsulates the supplied datagram if necessary,
  64.  * and then transmits it on its medium.
  65.  *
  66.  * On input, each interface unwraps the data received by it, and either
  67.  * places it on the input queue of a internetwork datagram routine
  68.  * and posts the associated software interrupt, or passes the datagram to a raw
  69.  * packet input routine.
  70.  *
  71.  * Routines exist for locating interfaces by their addresses
  72.  * or for locating a interface on a certain network, as well as more general
  73.  * routing and gateway routines maintaining information used to locate
  74.  * interfaces.  These routines live in the files if.c and route.c
  75.  */
  76.  
  77. #ifdef KERNEL            /* XXX: ifnet going away soon */
  78. #ifndef _TIME_ /*  XXX fast fix for SNMP, going away soon */
  79. #include <sys/time.h>
  80. #endif
  81.  
  82. /*
  83.  * Structure defining a queue for a network interface.
  84.  *
  85.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  86.  */
  87.  
  88. struct    ifqueue {
  89.   struct    mbuf *ifq_head;
  90.   struct    mbuf *ifq_tail;
  91.   int    ifq_len;
  92.   int    ifq_maxlen;
  93.   int    ifq_drops;
  94. };            
  95.  
  96. struct ifnet {
  97.     char    *if_name;        /* name, e.g. ``en'' or ``lo'' */
  98.     short    if_unit;        /* sub-unit for lower level driver */
  99.     short    if_mtu;            /* maximum transmission unit */
  100.     short    if_flags;        /* up/down, broadcast, etc. */
  101.     short    if_timer;        /* time 'til if_watchdog called */
  102.     int    if_metric;        /* routing metric (external only) */
  103.     struct    ifaddr *if_addrlist;    /* linked list of addresses per if */
  104.     struct  ifqueue if_snd;        /* output queue */
  105. /* procedure handles */
  106.     int    (*if_init)();        /* init routine */
  107.     int    (*if_output)(struct ifnet *,    /* output routine (enqueue) */
  108.                  struct mbuf *,
  109.                  struct sockaddr *, struct rtentry *);
  110.     int    (*if_start)();        /* initiate output routine */
  111.     int    (*if_done)();        /* output complete routine */
  112.     int    (*if_ioctl)(struct ifnet *, int, caddr_t); /* ioctl routine */
  113.     int    (*if_reset)();        /* bus reset routine */
  114.     int    (*if_watchdog)();    /* timer routine */
  115. /* generic interface statistics */
  116.     int    if_ipackets;        /* packets received on interface */
  117.     int    if_ierrors;        /* input errors on interface */
  118.     int    if_opackets;        /* packets sent on interface */
  119.     int    if_oerrors;        /* output errors on interface */
  120.     int    if_collisions;        /* collisions on csma interfaces */
  121. /* end statistics */
  122.     struct    ifnet *if_next;
  123.     u_char    if_type;        /* ethernet, tokenring, etc */
  124.     u_char    if_addrlen;        /* media address length */
  125.     u_char    if_hdrlen;        /* media header length */
  126.     u_char    if_index;        /* numeric abbreviation for this if  */
  127. /* more statistics here to avoid recompiling netstat */
  128.     struct    timeval if_lastchange;    /* last updated */
  129.     int    if_ibytes;        /* total number of octets received */
  130.     int    if_obytes;        /* total number of octets sent */
  131.     int    if_imcasts;        /* packets received via multicast */
  132.     int    if_omcasts;        /* packets sent via multicast */
  133.     int    if_iqdrops;        /* dropped on input, this interface */
  134.     int    if_noproto;        /* destined for unsupported protocol */
  135.     int    if_baudrate;        /* linespeed */
  136.         int    if_pcount;        /* number of promiscuous listeners */
  137. };
  138.  
  139. /*
  140.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  141.  * input routines have queues of messages stored on ifqueue structures
  142.  * (defined above).  Entries are added to and deleted from these structures
  143.  * by these macros, which should be called with ipl raised to splimp().
  144.  */
  145. #define    IF_QFULL(ifq)        ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  146. #define    IF_DROP(ifq)        ((ifq)->ifq_drops++)
  147. #define    IF_ENQUEUE(ifq, m) { \
  148.     (m)->m_nextpkt = 0; \
  149.     if ((ifq)->ifq_tail == 0) \
  150.         (ifq)->ifq_head = m; \
  151.     else \
  152.         (ifq)->ifq_tail->m_nextpkt = m; \
  153.     (ifq)->ifq_tail = m; \
  154.     (ifq)->ifq_len++; \
  155. }
  156. #define    IF_PREPEND(ifq, m) { \
  157.     (m)->m_nextpkt = (ifq)->ifq_head; \
  158.     if ((ifq)->ifq_tail == 0) \
  159.         (ifq)->ifq_tail = (m); \
  160.     (ifq)->ifq_head = (m); \
  161.     (ifq)->ifq_len++; \
  162. }
  163. #define    IF_DEQUEUE(ifq, m) { \
  164.     (m) = (ifq)->ifq_head; \
  165.     if (m) { \
  166.         if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
  167.             (ifq)->ifq_tail = 0; \
  168.         (m)->m_nextpkt = 0; \
  169.         (ifq)->ifq_len--; \
  170.     } \
  171. }
  172.  
  173. #define    IFQ_MAXLEN    50
  174. #define    IFNET_SLOWHZ    1        /* granularity is 1 second */
  175.  
  176. #endif /* KERNEL */
  177.  
  178. #define    IFF_UP        0x1        /* interface is up */
  179. #define    IFF_BROADCAST    0x2        /* broadcast address valid */
  180. #define    IFF_DEBUG    0x4        /* turn on debugging */
  181. #define    IFF_LOOPBACK    0x8        /* is a loopback net */
  182. #define    IFF_POINTOPOINT    0x10        /* interface is point-to-point link */
  183. #define    IFF_NOTRAILERS    0x20        /* avoid use of trailers */
  184. #define    IFF_RUNNING    0x40        /* resources allocated */
  185. #define    IFF_NOARP    0x80        /* no address resolution protocol */
  186. #define    IFF_SIMPLEX    0x800        /* can't hear own transmissions */
  187.  
  188. /* next two not supported now, but reserved: */
  189. #define    IFF_PROMISC    0x100        /* receive all packets */
  190. #define    IFF_ALLMULTI    0x200        /* receive all multicast packets */
  191. #define    IFF_OACTIVE    0x400        /* transmission in progress */
  192.  
  193. /* flags set internally only: */
  194. #define    IFF_CANTCHANGE \
  195.     (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|IFF_SIMPLEX)
  196.  
  197. #ifdef KERNEL            /* XXX: going away soon */
  198. /*
  199.  * The ifaddr structure contains information about one address
  200.  * of an interface.  They are maintained by the different address families,
  201.  * are allocated and attached when an address is set, and are linked
  202.  * together so all addresses for an interface can be located.
  203.  */
  204. struct ifaddr {
  205.     struct    sockaddr *ifa_addr;    /* address of interface */
  206.     struct    sockaddr *ifa_dstaddr;    /* other end of p-to-p link */
  207. #define    ifa_broadaddr    ifa_dstaddr    /* broadcast address interface */
  208.     struct    sockaddr *ifa_netmask;    /* used to determine subnet */
  209.     struct    ifnet *ifa_ifp;        /* back-pointer to interface */
  210.     struct    ifaddr *ifa_next;    /* next address for interface */
  211.     void    (*ifa_rtrequest)(int,     /* check or clean routes (+ or -)'d */
  212.                  struct rtentry *, struct sockaddr *);
  213.     struct     rtentry *ifa_rt;    /* ??? for ROUTETOIF */
  214.     u_short    ifa_flags;        /* mostly rt_flags for cloning */
  215.     u_short    ifa_llinfolen;        /* extra to malloc for link info */
  216. };
  217. #define IFA_ROUTE    RTF_UP        /* route installed */
  218.  
  219. #endif /* KERNEL */
  220.  
  221. /*
  222.  * Interface request structure used for socket
  223.  * ioctl's.  All interface ioctl's must have parameter
  224.  * definitions which begin with ifr_name.  The
  225.  * remainder may be interface specific.
  226.  */
  227. struct    ifreq {
  228. #define    IFNAMSIZ    16
  229.     char    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  230.     union {
  231.         struct    sockaddr ifru_addr;
  232.         struct    sockaddr ifru_dstaddr;
  233.         struct    sockaddr ifru_broadaddr;
  234.         short    ifru_flags;
  235.         int    ifru_metric;
  236.         caddr_t    ifru_data;
  237.     } ifr_ifru;
  238. #define    ifr_addr    ifr_ifru.ifru_addr    /* address */
  239. #define    ifr_dstaddr    ifr_ifru.ifru_dstaddr    /* other end of p-to-p link */
  240. #define    ifr_broadaddr    ifr_ifru.ifru_broadaddr    /* broadcast address */
  241. #define    ifr_flags    ifr_ifru.ifru_flags    /* flags */
  242. #define    ifr_metric    ifr_ifru.ifru_metric    /* metric */
  243. #define    ifr_data    ifr_ifru.ifru_data    /* for use by interface */
  244. };
  245.  
  246. struct ifaliasreq {
  247.     char    ifra_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  248.     struct    sockaddr ifra_addr;
  249.     struct    sockaddr ifra_broadaddr;
  250.     struct    sockaddr ifra_mask;
  251. };
  252.  
  253. /*
  254.  * Structure used in SIOCGIFCONF request.
  255.  * Used to retrieve interface configuration
  256.  * for machine (useful for programs which
  257.  * must know all networks accessible).
  258.  */
  259. struct    ifconf {
  260.     int    ifc_len;        /* size of associated buffer */
  261.     union {
  262.         caddr_t    ifcu_buf;
  263.         struct    ifreq *ifcu_req;
  264.     } ifc_ifcu;
  265. #define    ifc_buf    ifc_ifcu.ifcu_buf    /* buffer address */
  266. #define    ifc_req    ifc_ifcu.ifcu_req    /* array of structures returned */
  267. };
  268.  
  269. #ifndef IF_ARP_H
  270. #include <net/if_arp.h>
  271. #endif
  272.  
  273. #ifdef KERNEL
  274. extern struct    ifnet *ifnet;
  275. extern struct    ifqueue rawintrq;        /* raw packet input queue */
  276. #include <net/if_protos.h>
  277. #include <net/if_loop_protos.h>
  278. #endif /* KERNEL */
  279.  
  280. #endif /* IF_H */
  281.